package com.yinhd.study.dockingPlatform;

import com.yinhd.study.dockingPlatform.platform.Platform;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.InvocationTargetException;

public class PlatformFactory implements FactoryBean<Platform> {
    //通过反射弥补简单工厂 不符合开闭原则
    //单一原则 只放连接使用的属性
    public static  Platform getPlatform(Class c){
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
//        context.getBean("Service");
        Platform platform = null;
        try {
            platform = (Platform) c.getDeclaredConstructor().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return platform;
    }

    @Override
    public Platform getObject() throws Exception {
        return null;
    }

    @Override
    public Class<?> getObjectType() {
        return null;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
